import { reqUserAddressList, reqGetOrderInfo } from '@/api'

const state = {
    address: [],
    orderInfo: {}
}
const mutations = {
    GETUSERADDRESS(state, address) {
        state.address = address;
    },
    GETORDERINFO(state, orderInfo) {
        state.orderInfo = orderInfo
    }
}
const actions = {
    //获取用户地址信息
    async getUserAddress({ commit }) {
        let result = await reqUserAddressList()
        if (result.code == 200) {
            commit('GETUSERADDRESS', result.data)
            return 'ok'
        } else {
            return Promise.reject(new Error('fail'))
        }

    },
    //获取用户交易信息
    async getOrderInfo({ commit }) {
        let result = await reqGetOrderInfo();
        if (result.code == 200) {
            commit('GETORDERINFO', result.data)
            return 'ok'
        } else {
            return Promise.reject(new Error('fail'))
        }
    }
}
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters
}